import axios from 'axios';
import * as actionTypes from './actionTypes';

export const logout = () => {
  return {
    type: actionTypes.LOGOUT,
    value: false
  }
}

export const login = (account, password) => {
  return (dispatch) => {
    axios.get('/api/login.json?account='+account+'&password='+password).then((res) => {
      console.log(res.data);
      const result = res.data
      if (result.success) {
        dispatch(changLogin(result.data))
      } else {
        alert('登陆失败');
      }
    })
  }
}

const changLogin = (data) => {
  return {
    type: actionTypes.CHANGE_LOGIN_DATA,
    value: data
  }
}